import BaseUIMediator from "../../UIExt/FGui/BaseUIMediator";
import LTUI from "../../UIExt/LTUI";
import UI_CommonUI from "../../ui/Main/UI_CommonUI";
import UI_MoudleDemoMediator from "./UI_MoudleDemoMediator";
import RollOpenData from "../../UIExt/UISrc/Data/RollOpenData";
import SetOpenData from "../../UIExt/UISrc/Data/SetOpenData";
import TrySkinOpenData from "../../UIExt/UISrc/Data/TrySkinOpenData";
import OfflineOpenData from "../../UIExt/UISrc/Data/OfflineOpenData";
import { EndLoseOpenData } from "../../UIExt/UISrc/Data/EndLoseOpenData";
import EndRewardOpenData from "../../UIExt/UISrc/Data/EndRewardOpenData";
import EndShareOpenData from "../../UIExt/UISrc/Data/EndShareOpenData";
import OneMoreOpenData from "../../UIExt/UISrc/Data/OneMoreOpenData";
import SignOpenData from "../../UIExt/UISrc/Data/SignOpenData";
import { UnlockProgressOpenData } from "../../UIExt/UISrc/Data/UnlockProgressOpenData";

export default class UI_CommonUIMediator extends BaseUIMediator<UI_CommonUI> {

    private static _instance: UI_CommonUIMediator;
    public static get instance(): UI_CommonUIMediator {
        if (this._instance == null) {
            this._instance = new UI_CommonUIMediator();
            this._instance._classDefine = UI_CommonUI;
        }
        return this._instance;
    }

    _OnShow() {
        super._OnShow();
        // your code
        this.ui.m_btn_back.onClick(this, this._OnClickBack);
        this.ui.m_btn_sign.onClick(this, this._OnClickSign);
        this.ui.m_btn_endshare.onClick(this, this._OnClickEndShare);
        this.ui.m_btn_endreward.onClick(this, this._OnClickEndReward);
        this.ui.m_btn_offline.onClick(this, this._OnClickOffline);
        this.ui.m_btn_tryskin.onClick(this, this._OnClickTrySkin);
        this.ui.m_btn_set.onClick(this, this._OnClickSet);
        this.ui.m_btn_roll.onClick(this, this._OnClickRoll);
        this.ui.m_btn_onemore.onClick(this, this._OnClickOneMore);
        this.ui.m_btn_moudle.onClick(this, this._OnClickModule);
        this.ui.m_btn_endlose.onClick(this, this._OnClickEndLose);
        this.ui.m_btn_unlockprogress.onClick(this, this._OnClickUnlockProgress);
        this.ui.m_btn_bonus.onClick(this, LTUI.ShowBonusBox);
        this.ui.m_btn_exskin.onClick(this, LTUI.ShowExSKin);
    }

    private _OnClickModule() {
        // LTUI.Toast('完善中');
        // return;
        UI_MoudleDemoMediator.instance.Show();
    }

    private _OnClickRoll() {
        let openData = new RollOpenData();
        openData.onRolled = Laya.Handler.create(null, (index: number, fromObj: fgui.GObject) => {
            LTUI.Toast("转中" + index);
        }, null, false);
        LTUI.ShowRoll(openData);
    }

    private _OnClickSet() {
        let openData = new SetOpenData();
        openData.onToggleChange = Laya.Handler.create(null, () => {
            LTUI.Toast("改变设置");
        }, null, false);
        LTUI.ShowSet(openData);
    }

    private _OnClickTrySkin() {
        let openData = new TrySkinOpenData();
        console.error('demo 数据');
        openData.iconPaths = ['test/test.png'];
        openData.onClose = Laya.Handler.create(null, (type: number, ) => {
            if (type < 0) {
                LTUI.Toast("不试用皮肤");
            } else {
                LTUI.Toast("试用皮肤" + type);
            }
        });
        LTUI.ShowTrySkin(openData);
    }

    private _OnClickOffline() {
        let openData = new OfflineOpenData();
        openData.onClose = Laya.Handler.create(null, (type: number, fromObj: fgui.GObject) => {
            switch (type) {
                case 0:
                    LTUI.Toast("单倍领取");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                case 1:
                    LTUI.Toast("双倍领取");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                default:
                    LTUI.Toast("未处理相应类型" + type);
                    break;
            }
        });
        LTUI.ShowOffline(openData);
    }

    private _OnClickEndLose() {
        let openData = new EndLoseOpenData();
        openData.onClose = Laya.Handler.create(null, (type: number) => {
            switch (type) {
                case 0:
                    LTUI.Toast("点击重新开始");
                    break;
                case 1:
                    LTUI.Toast("观看视频跳过");
                    break;
            }
        });
        LTUI.ShowEndLose(openData);
    }

    private _OnClickEndReward() {
        let openData = new EndRewardOpenData();
        // openData.enableShowGames = false;
        openData.onClose = Laya.Handler.create(null, (type: number, fromObj: fgui.GObject) => {
            switch (type) {
                case 0:
                    LTUI.Toast("单倍领取");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                case 1:
                    LTUI.Toast("多倍领取");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                case 2:
                    LTUI.Toast("点击返回");
                    break;
                default:
                    LTUI.Toast("未处理相应类型" + type);
                    break;
            }
        });
        LTUI.ShowEndReward(openData);
    }

    private _OnClickEndShare() {
        let openData = new EndShareOpenData();
        openData.onClose = Laya.Handler.create(null, (type: number, fromObj: fgui.GObject) => {
            switch (type) {
                case 0:
                    LTUI.Toast("未分享");
                    break;
                case 1:
                    LTUI.Toast("已分享");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                default:
                    LTUI.Toast("未处理相应类型" + type);
                    break;
            }
        });
        LTUI.ShowEndShare(openData);
    }

    private _OnClickOneMore() {
        let openData = new OneMoreOpenData();
        openData.onClose = Laya.Handler.create(null, (type: number, fromObj: fgui.GObject) => {
            switch (type) {
                case 0:
                    LTUI.Toast("点击了关闭按钮");
                    break;
                case 1:
                    LTUI.Toast("点击了普通领取按钮");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                case 2:
                    LTUI.Toast("点击了双倍领取按钮");
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                default:
                    LTUI.Toast("未处理相应类型" + type);
                    break;
            }
        });
        LTUI.ShowOneMore(openData);
    }

    private _OnClickSign() {
        let openData = new SignOpenData();
        // 强制未签到
        openData.isSigned = false;
        openData.onClose = Laya.Handler.create(null, (type: number, fromObj: fgui.GObject, dayCount: number) => {
            switch (type) {
                case 0:
                    LTUI.Toast("点击了关闭按钮");
                    break;
                case 1:
                    LTUI.Toast("点击了普通领取按钮" + dayCount);
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                case 2:
                    LTUI.Toast("点击了双倍领取按钮" + dayCount);
                    LTUI.FlyCoinsTo(fromObj, this.ui.m_title);
                    break;
                default:
                    LTUI.Toast("未处理相应类型" + type);
                    break;
            }
        });
        LTUI.ShowSignUI(openData);
    }

    private _OnClickUnlockProgress() {
        let openData = new UnlockProgressOpenData();
        openData.endProgress = 100;

        openData.onClose = Laya.Handler.create(null, (type: number) => {
            switch (type) {
                case 0:
                    LTUI.Toast("点击正常关闭");
                    break;
                case 1:
                    LTUI.Toast("点击视频领取");
                    break;
                case 2:
                    LTUI.Toast("点击正常领取");
                    break;
            }
        });
        LTUI.ShowUnlockProgress(openData);
    }

    private _OnClickBack() {
        this.Hide();
    }

}